﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxCallback;
using SGRapidForm.Common;
using SGRapidForm.Permission.Service.Interface;
using System.Collections.Specialized;
using SGRapidForm.Permission.Entity;

namespace SGDemo.Web
{
    public partial class FillQuestion : System.Web.UI.Page
    {
        private IPermissionService _permissionService = ServiceProxyFactory.Create<IPermissionService>("permissionservice");

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 提交密保信息
        /// </summary>
        protected void cabExecute_Callback(object sender, CallbackEventArgs e)
        {
            NameValueCollection parameters = HttpUtility.ParseQueryString(e.Parameter);
            UserDetails user = _permissionService.User_GetByKeyid(ApplicationContext.Current.UserKeyid);
            if (parameters["PasswordQuestion"] == "0")
            {
                user.PasswordQuestion = parameters["CustomPasswordQuestion"];
            }
            else 
            {
                user.PasswordQuestion = parameters["PasswordQuestion"];
            }
            
            user.PasswordAnswer = parameters["PasswordAnswer"];
            user.Email = parameters["Email"];
            bool ret =  _permissionService.User_Update(user);

            if (ret)
            {
                //设置当前登录人的密保信息
                ApplicationContext.Current.PasswordQuestion = user.PasswordQuestion;
                ApplicationContext.Current.PasswordAnswer = user.PasswordAnswer;
                e.Result = "Success"; 
            }
        }
    }
}